﻿// Doc-Encode UTF8-BOM, Space(4), Unix(LF)
#include "hiobj.h"
#include "hiobj_in.h"
#include "hiobj_help.h"
#include "himpp_extension.h"
#include "klbutil/CMap.hpp"
#include <assert.h>

#include "hi_common.h"


// MPP_VERSION_S
static int map2obj_MPP_VERSION_S(hiobj_t* p_dst, klb::CMap& src)
{
    klb::CMap& r = src;
    MPP_VERSION_S* p_cfg = (MPP_VERSION_S*)p_dst->data;

    cmap_get_HI_CHAR(r, "Version", p_cfg->aVersion, VERSION_NAME_MAXLEN);

    return 0;
}

static int obj2map_MPP_VERSION_S(klb::CMap& dst, hiobj_t* p_src)
{
    klb::CMap& r = dst;
    const MPP_VERSION_S* p_cfg = (const MPP_VERSION_S*)p_src->data;

    r["Version"] = p_cfg->aVersion;

    return 0;
}

// MPP_CHN_S
static int map2obj_MPP_CHN_S(hiobj_t* p_dst, klb::CMap& src)
{
    klb::CMap& r = src;
    MPP_CHN_S* p_chn = (MPP_CHN_S*)p_dst->data;

    cmap_get_ENUM(r, "ModId", &p_chn->enModId);
    cmap_get_HI_S32(r, "DevId", &p_chn->s32DevId);
    cmap_get_HI_S32(r, "ChnId", &p_chn->s32ChnId);

    return 0;
}

static int obj2map_MPP_CHN_S(klb::CMap& dst, hiobj_t* p_src)
{
    klb::CMap& r = dst;
    const MPP_CHN_S* p_chn = (const MPP_CHN_S*)p_src->data;

    r["ModId"] = (int64_t)p_chn->enModId;
    r["DevId"] = (int64_t)p_chn->s32DevId;
    r["ChnId"] = (int64_t)p_chn->s32ChnId;

    return 0;
}

//////////////////////////////////////////////////////////////////////////


int load_hiobj_common(himpp_extension_t* p_ex)
{
    static hiobj_reg_t reg[] =
    {
        { "MPP_VERSION_S",      sizeof(MPP_VERSION_S),      map2obj_MPP_VERSION_S ,     obj2map_MPP_VERSION_S },
        { "MPP_CHN_S",          sizeof(MPP_CHN_S),          map2obj_MPP_CHN_S ,         obj2map_MPP_CHN_S },

        { NULL, 0,  NULL, NULL }
    };

    himpp_ex_add(p_ex, reg);

    return 1;
}
